package com.frost.book.mapper;

import com.frost.book.model.BookInfo;
import com.frost.book.model.PageRequest;
import com.frost.book.model.PageResult;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    /**
     * 添加图书
     * @param bookInfo
     * @return
     */
    @Insert("insert into book_info (book_name, author, count, price, publish, status) " +
            "values (#{bookName}, #{author}, #{count}, #{price}, #{publish}, #{status})")
    Integer insertBook(BookInfo bookInfo);

    /**
     * 查询有效图书数据总数
     */
    @Select("select count(1) from book_info where `status` <> 0")
    Integer count();

    /**
     * 查询当前页图书列表数据
     */
    @Select("select * from book_info where `status` <> 0 order by id desc limit #{offset}, #{pageSize}")
    List<BookInfo> select(PageRequest pageRequest);

    /**
     * 根据id查询图书信息
     */
    @Select("select * from book_info where `status` <> 0 and id = #{id}")
    BookInfo selectByBookId(Integer id);

    /**
     * 根据id修改图书信息
     */
//    @Update("update book_info set book_name = #{bookName}, author = #{author}, count = #{count}, price = #{price}, publish = #{publish}, status = #{status} where id = #{id}")
//    Integer updateBook(@Param("bookInfo") BookInfo bookInfo);
    Integer updateBook(BookInfo bookInfo);


    Integer batchDelete(@Param("ids") List<Integer> ids);
}
